/**
 * 
 */
package com.alstudio.ui.module.voip;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.alstudio.utils.android.device.ALDisplayMetricsManager;
import com.alstudio.utils.asyncTask.ALAsycTask;
import com.alstudio.utils.asyncTask.ALAsyncTaskCallback;
import com.alstudio.utils.log.ALLog;
import com.alstudio.view.ViewUtils;
import com.loovee.imaohu.R;

/**
 * @author alonso lee
 * 
 */
public class MeteorView2 extends FrameLayout {

	private ArrayList<ImageView> meteors = new ArrayList<ImageView>();
	private HashMap<ImageView, Animation> anims = new HashMap<ImageView, Animation>();

	private Context mContext;

	private int numMeteors = 0;

	private boolean isDestroyRequest = false;

	private boolean isInitDone = false;

	/**
	 * @param context
	 */
	public MeteorView2(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.mContext = context;
	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		// TODO Auto-generated method stub
		super.onSizeChanged(w, h, oldw, oldh);
	}

	public void addMeteor(final int num) {
		numMeteors = num;
		new Handler().post(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				for (int i = 0; i < num; ++i) {
					// ImageView child = createMeteors(meteorImg);
					// if (isDestroyRequest) {
					// return;
					// }
					ALAsycTask task = new ALAsycTask(addViewCallback);
					task.execute(i);
					// ImageView child = createFlash(i);
					// child.setAnimation(getMeteorFlyAnimationSet());
					// meteors.add(child);
					// addView(child, getLayoutParamsForMeterLight());
					// addView(child);
				}
				// isInitDone = true;
				// if (isDestroyRequest) {
				// destroy();
				// }
			}
		});
	}

	private ALAsyncTaskCallback addViewCallback = new ALAsyncTaskCallback() {

		@Override
		public Object onTaskStart(Object obj) {
			// TODO Auto-generated method stub
			int i = (Integer) obj;
			ImageView child = createFlash(i);
			// child.setAnimation(getMeteorFlyAnimationSet());
			meteors.add(child);
			if (numMeteors == meteors.size()) {
				isInitDone = true;
				if (isDestroyRequest) {
					destroy();
				}

			}
			return child;
		}

		@Override
		public Object onTaskFinish(Object obj) {
			// TODO Auto-generated method stub
			ImageView child = (ImageView) obj;
			// ViewUtils.goneView(child);
			addView(child);
			return null;
		}

		@Override
		public Object onTaskCancel() {
			// TODO Auto-generated method stub
			return null;
		}
	};

	public void destroy() {
		isDestroyRequest = true;
		// new Thread() {
		// public void run()
		{
			// for (ImageView v : meteors) {
			// v.clearAnimation();
			// v.setImageBitmap(null);
			// v = null;
			// }
			if (!isInitDone)
				return;
			meteors.clear();
			meteors = null;
			anims.clear();
			anims = null;
			ALLog.d(getClass().getSimpleName() + " 销毁完毕 ");
		}
		;
		// }.start();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.view.View#onWindowFocusChanged(boolean)
	 */
	@Override
	public void onWindowFocusChanged(boolean hasWindowFocus) {
		// TODO Auto-generated method stub
		super.onWindowFocusChanged(hasWindowFocus);
		if (hasWindowFocus) {
			// for (ImageView child : meteors) {
			// ALLog.d("坐标轴 " + child.getY());
			// AnimationSet set = null;
			// if (child.getY() > ALDisplayMetricsManager
			// .getScreenHeight(mContext) / 2) {
			// ALLog.d("在屏幕下方");
			// set = getMeteorFlyAnimationSet(false);
			// } else {
			// ALLog.d("在屏幕上方");
			// set = getMeteorFlyAnimationSet(true);
			// }
			// anims.put(child, set);
			// }
		}

	}

	public void resume() {
		if (anims.size() > 0) {
			// for (ImageView child : meteors) {
			// child.startAnimation(anims.get(child));
			// }

			ArrayList<ImageView> tmp = new ArrayList<ImageView>();
			tmp.addAll(meteors);
			for (ImageView child : tmp) {
				// child.clearAnimation();
				ViewUtils.showView(child);
				child.startAnimation(anims.get(child));

			}
			tmp.clear();
			tmp = null;
		}
	}

	public void pause() {
		ArrayList<ImageView> tmp = new ArrayList<ImageView>();
		tmp.addAll(meteors);
		for (ImageView child : tmp) {
			child.clearAnimation();
		}
		tmp.clear();
		tmp = null;
	}

	private FrameLayout.LayoutParams getLayoutParamsForMeterLight2(int num) {

		FrameLayout.LayoutParams p = new FrameLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

		Random random = new Random();// 指定种子数字

		int marginTop = 0;
		int marginBottom = 0;
		int marginLeft = 0;
		int marginRight = 0;
		int divisor = random.nextInt(3) + 1;
		int div = random.nextInt(3) + 1;

		int dir = num % 8;
		int marginV = ALDisplayMetricsManager.getScreenHeight(mContext) / 2 / 8;
		int marginH = ALDisplayMetricsManager.getScreenWidth(mContext) / 2 / 8;
		marginV = 1;
		marginH = 1;

		switch (dir) {
		case 0:
			// 左上角
			p.gravity = Gravity.CENTER;
			marginBottom = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;

			if (marginBottom > ALDisplayMetricsManager
					.getScreenHeight(mContext) / 2) {
				marginBottom /= marginV;
			}

			marginRight = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) /* / div */) + marginH/* + 10 */;

			break;
		case 1:
			// 右上角
			p.gravity = Gravity.CENTER;
			marginLeft = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) /* / div */) + marginH /* + 10 */;

			marginBottom = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;

			if (marginBottom > ALDisplayMetricsManager
					.getScreenHeight(mContext) / 2) {
				marginBottom /= marginV;
			}

			break;
		case 2:
			// 左下角
			p.gravity = Gravity.BOTTOM | Gravity.LEFT;
			p.gravity = Gravity.CENTER;

			marginRight = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) /* / div */) + marginH /* + 10 */;
			marginTop = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / divisor)
					+ marginV;
			if (marginTop > ALDisplayMetricsManager.getScreenHeight(mContext) / 2) {
				marginTop /= marginV;
			}

			break;
		case 3:
			// 右下角
			p.gravity = Gravity.BOTTOM | Gravity.RIGHT;
			p.gravity = Gravity.CENTER;

			marginTop = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / divisor)
					+ marginV;
			if (marginTop > ALDisplayMetricsManager.getScreenHeight(mContext) / 2) {
				marginTop /= marginV;
			}

			marginLeft = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) /* / div */) + marginH /* + 10 */;

			break;
		case 4:
			p.gravity = Gravity.CENTER_HORIZONTAL;
			p.gravity = Gravity.CENTER;

			marginBottom = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;
			if (marginBottom > ALDisplayMetricsManager
					.getScreenHeight(mContext) / 4) {
				marginBottom /= marginV;
			}

			break;
		case 5:
			p.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
			p.gravity = Gravity.CENTER;

			marginTop = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;
			if (marginTop > ALDisplayMetricsManager.getScreenHeight(mContext) / 4) {
				marginTop /= 4;
			}
			break;
		case 6:
			// 中间偏左
			p.gravity = Gravity.CENTER;
			marginRight = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) /* / div */) + marginH;
			break;
		case 7:
			// 中间偏右
			p.gravity = Gravity.CENTER;
			marginLeft = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) /* / div */) + marginH;
			break;
		}

		ALLog.d("第几个 " + dir);
		// marginLeft = 0;
		// marginTop = 0;
		// marginRight = 0;
		// marginBottom = 0;
		p.setMargins(marginLeft, marginTop, marginRight, marginBottom);
		return p;
	}

	/**
	 * 流星雨夜扫把飞的set
	 * 
	 * @param isNeedTrans
	 * @param isUp
	 * @return
	 */
	private AnimationSet getMeteorFlyAnimationSet2(int num) {
		AnimationSet set = new AnimationSet(true);
		LinearInterpolator lir = new LinearInterpolator();
		// AccelerateDecelerateInterpolator lir = new
		// AccelerateDecelerateInterpolator();

		Random random = new Random();// 指定种子数字

		long duration = 1000;

		duration = (random.nextInt(8) + 12) * 150;
		TranslateAnimation down = null;

		TranslateAnimation turn = null;

		int dir = num % 8;

		float y = /* 0.5f + */random.nextFloat();
		if (y > 0.5f) {
			// y = random.nextFloat();
			y = 1.0f - y;
		}
		// if (y > 0.5) {
		// y = 0.3f;
		// }

		ALLog.d("y-- " + y);
		boolean isLeft = random.nextInt(2) % 2 == 0 ? true : false;

		ScaleAnimation mScaleAnimation = new ScaleAnimation(0.0f, 0.8f, 0.0f,
				0.8f, Animation.RELATIVE_TO_PARENT, 0.0f,
				Animation.RELATIVE_TO_PARENT, 0.0f);
		mScaleAnimation.setDuration(duration);
		mScaleAnimation.setRepeatCount(Animation.INFINITE);
		mScaleAnimation.setRepeatMode(Animation.RESTART);

		switch (dir) {
		case 0:
			// 左上角
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /*-y * 2*/-1.0f,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /*-1.0f*/-0.3f);

			break;
		case 1:
			// 右上角
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /* y * 2 */1.0f,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, -y/* -1.0f - 0.3f-y */);

			break;
		case 2:
			// 左下角
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, -y * 2,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /* 0.3f y */1.0f);

			break;
		case 3:
			// 右下角
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y * 2,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /* 0.3f y */1.0f);

			break;
		case 4:
			if (isLeft) {
				y = -y;
			}
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /*-0.3f-y*/-1.0f);

			break;
		case 5:
			if (isLeft) {
				y = -y;
			}
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /* 0.3f y */1.0f);

			break;
		case 6:
			if (isLeft) {
				y = -y;
			}
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, -1.0f,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y/* - 0.3f-y */);
			ALLog.d("向左飞");
			break;
		case 7:
			if (isLeft) {
				y = -y;
			}
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, 1.0f,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y/* - 0.3f-y */);
			ALLog.d("向右飞");
			break;
		}

		down.setDuration(duration);
		down.setRepeatCount(Animation.INFINITE);
		down.setRepeatMode(Animation.RESTART);
		down.setInterpolator(lir);

		set.addAnimation(down);

		set.addAnimation(mScaleAnimation);

		random = new Random();// 指定种子数字

		// if (turn != null) {
		// turn.setDuration(duration);
		// turn.setRepeatCount(Animation.INFINITE);
		// turn.setRepeatMode(Animation.RESTART);
		// turn.setInterpolator(lir);
		//
		// set.addAnimation(turn);
		// }

		AlphaAnimation alph = new AlphaAnimation(1.0f, 0);

		alph.setDuration(duration);

		alph.setRepeatCount(Animation.INFINITE);
		alph.setRepeatMode(Animation.RESTART);
		alph.setInterpolator(lir);
		// set.addAnimation(alph);

		set.setInterpolator(lir);
		set.setStartOffset(random.nextInt(100) * 5 + (num * 2));

		return set;
	}

	private int v = 0, h = 0;

	private FrameLayout.LayoutParams getLayoutParamsForMeterLight3(int num) {

		FrameLayout.LayoutParams p = new FrameLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

		Random random = new Random();// 指定种子数字

		int marginTop = 0;
		int marginBottom = 0;
		int marginLeft = 0;
		int marginRight = 0;
		int divisor = random.nextInt(3) + 1;
		int div = random.nextInt(3) + 1;

		int dir = num % 4;
		int marginV = ALDisplayMetricsManager.getScreenHeight(mContext) / 2 / 8;
		int marginH = ALDisplayMetricsManager.getScreenWidth(mContext) / 2 / 8;
		marginV = 2;
		marginH = 2;
		// //横向距离
		// int h = 0;
		// //纵向距离
		// int v = 0;

		div = 2;
		switch (dir) {
		case 0:
			// 左上角
			p.gravity = Gravity.CENTER;
			marginBottom = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;

			if (marginBottom > ALDisplayMetricsManager
					.getScreenHeight(mContext) / 2) {
				marginBottom /= marginV;
			}

			marginRight = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) / div /* / div */)
					+ marginH/* + 10 */;

			break;
		case 1:
			// 右上角
			p.gravity = Gravity.CENTER;
			marginLeft = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) / div)
					+ marginH /* + 10 */;

			marginBottom = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;

			if (marginBottom > ALDisplayMetricsManager
					.getScreenHeight(mContext) / 2) {
				marginBottom /= marginV;
			}

			break;
		case 2:
			// 左下角
			p.gravity = Gravity.BOTTOM | Gravity.LEFT;
			p.gravity = Gravity.CENTER;

			marginRight = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) / div)
					+ marginH /* + 10 */;
			marginTop = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;
			if (marginTop > ALDisplayMetricsManager.getScreenHeight(mContext) / 2) {
				marginTop /= marginV;
			}

			break;
		case 3:
			// 右下角
			p.gravity = Gravity.BOTTOM | Gravity.RIGHT;
			p.gravity = Gravity.CENTER;

			marginTop = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;
			if (marginTop > ALDisplayMetricsManager.getScreenHeight(mContext)
					/ div) {
				marginTop /= marginV;
			}

			marginLeft = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) / div)
					+ marginH /* + 10 */;

			break;
		case 4:
			p.gravity = Gravity.CENTER_HORIZONTAL;
			p.gravity = Gravity.CENTER;

			marginBottom = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;
			if (marginBottom > ALDisplayMetricsManager
					.getScreenHeight(mContext) / 4) {
				marginBottom /= marginV;
			}

			break;
		case 5:
			p.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
			p.gravity = Gravity.CENTER;

			marginTop = random.nextInt(ALDisplayMetricsManager
					.getScreenHeight(mContext) / div)
					+ marginV;
			if (marginTop > ALDisplayMetricsManager.getScreenHeight(mContext) / 4) {
				marginTop /= 4;
			}
			break;
		case 6:
			// 中间偏左
			p.gravity = Gravity.CENTER;
			marginRight = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) /* / div */) + marginH;
			break;
		case 7:
			// 中间偏右
			p.gravity = Gravity.CENTER;
			marginLeft = random.nextInt(ALDisplayMetricsManager
					.getScreenWidth(mContext) /* / div */) + marginH;
			break;
		}

		ALLog.d("第几个 " + dir);
		// marginLeft = 0;
		// marginTop = 0;
		// marginRight = 0;
		// marginBottom = 0;

		if (marginTop != 0) {
			v = marginTop;
		} else {
			v = marginBottom;
		}

		if (marginLeft != 0) {
			h = marginLeft;
		} else {
			h = marginRight;
		}

		p.setMargins(marginLeft, marginTop, marginRight, marginBottom);
		return p;
	}

	/**
	 * 流星雨夜扫把飞的set
	 * 
	 * @param isNeedTrans
	 * @param isUp
	 * @return
	 */
	private AnimationSet getMeteorFlyAnimationSet3(int num) {
		AnimationSet set = new AnimationSet(true);
		AccelerateInterpolator lir = new AccelerateInterpolator();

		Random random = new Random();// 指定种子数字

		long duration = 1000;

		duration = (random.nextInt(8) + 12) * 150;
		TranslateAnimation down = null;

		TranslateAnimation turn = null;

		int dir = num % 4;

		float y = /* 0.5f + */random.nextFloat();
		if (y > 0.5f) {
			// y = random.nextFloat();
			y = 1.0f - y;
		}

		float x = 0f;
		int hDiv = (ALDisplayMetricsManager.getScreenWidth(mContext) /*/ 2*/);
		int vDiv = (ALDisplayMetricsManager.getScreenHeight(mContext) /*/ 2*/);

		ALLog.d("hh " + h + " vv " + v + " width " + hDiv + " height " + vDiv);
		if (h > hDiv) {
			h -= hDiv;
		}

		if (v > vDiv) {
			v -= vDiv;
		}
		ALLog.d("hs " + (float) h / hDiv);
		x = (float) h / (ALDisplayMetricsManager.getScreenWidth(mContext) /*/ 2*/);
		ALLog.d("xxxx " + x);
		y = (float) v / ALDisplayMetricsManager.getScreenHeight(mContext) /*/ 2*/;

		boolean isLeft = random.nextInt(2) % 2 == 0 ? true : false;

		ScaleAnimation mScaleAnimation = new ScaleAnimation(0.0f, 1.2f, 0.0f,
				1.2f, Animation.RELATIVE_TO_PARENT, 0.0f,
				Animation.RELATIVE_TO_PARENT, 0.0f);
		mScaleAnimation.setDuration(duration);
		mScaleAnimation.setRepeatCount(Animation.INFINITE);
		mScaleAnimation.setRepeatMode(Animation.RESTART);
		// y = 1.0f;
		// x = 0.3f;
		// x = 1.0f - x;
		// y = 1.0f - y;
		y = 1.0f;
		switch (dir) {
		case 0:
			// 左上角
			x = -x;
			y = -y;
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /*-y * 2*/x,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /*-1.0f*/y);

			break;
		case 1:
			// 右上角
			y = -y;
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /* y * 2 */x,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y/* -1.0f - 0.3f-y */);

			break;
		case 2:
			// 左下角
			x = -x;
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, x,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /* 0.3f y */y);

			break;
		case 3:
			// 右下角
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, x,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /* 0.3f y */y);

			break;
		case 4:
			if (isLeft) {
				y = -y;
			}
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /*-0.3f-y*/-1.0f);

			break;
		case 5:
			if (isLeft) {
				y = -y;
			}
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, /* 0.3f y */1.0f);

			break;
		case 6:
			if (isLeft) {
				y = -y;
			}
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, -1.0f,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y/* - 0.3f-y */);
			ALLog.d("向左飞");
			break;
		case 7:
			if (isLeft) {
				y = -y;
			}
			down = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, 1.0f,
					Animation.RELATIVE_TO_PARENT, 0,
					Animation.RELATIVE_TO_PARENT, y/* - 0.3f-y */);
			ALLog.d("向右飞");
			break;
		}

		down.setDuration(duration);
		down.setRepeatCount(Animation.INFINITE);
		down.setRepeatMode(Animation.RESTART);
		down.setInterpolator(lir);

		set.addAnimation(down);

		set.addAnimation(mScaleAnimation);

		random = new Random();// 指定种子数字

		// if (turn != null) {
		// turn.setDuration(duration);
		// turn.setRepeatCount(Animation.INFINITE);
		// turn.setRepeatMode(Animation.RESTART);
		// turn.setInterpolator(lir);
		//
		// set.addAnimation(turn);
		// }

		AlphaAnimation alph = new AlphaAnimation(1.0f, 0.5f);

		alph.setDuration(3 * duration / 4);

		alph.setRepeatCount(Animation.INFINITE);
		alph.setRepeatMode(Animation.RESTART);
		alph.setStartOffset(3 * duration / 4);
		// alph.setInterpolator(lir);
		// set.addAnimation(alph);

		// set.setInterpolator(lir);
		set.setStartOffset(random.nextInt(100) * 5 + (num * 2));

		return set;
	}

	private ImageView createFlash(int num) {
		ImageView img = new ImageView(mContext);
		Random random = new Random();// 指定种子数字

		int leftOrRight = random.nextInt(5) + 1;
		ALLog.d("leftOrRight " + leftOrRight);
		switch (leftOrRight) {
		case 0:
			img.setImageResource(R.drawable.meet_flash_star_01);
			break;
		case 1:
			img.setImageResource(R.drawable.meet_flash_star_02);
			break;
		case 2:
			img.setImageResource(R.drawable.meet_flash_star_01);
			break;
		case 3:
			img.setImageResource(R.drawable.meet_flash_star_02);
			break;
		case 4:
			img.setImageResource(R.drawable.meet_flash_star_01);
			break;
		}

		FrameLayout.LayoutParams p = getLayoutParamsForMeterLight2(num);
		img.setLayoutParams(p);
		AnimationSet set = null;
		set = getMeteorFlyAnimationSet2(num);
		anims.put(img, set);
		return img;
	}

}
